package com.ouheng.shop.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ouheng.common.utils.PageUtils;
import com.ouheng.common.utils.Query;
import com.ouheng.shop.domain.OhOrderDO;
import com.ouheng.shop.domain.OrderProductDO;
import com.ouheng.shop.service.OhOrderService;
import com.ouheng.shop.service.StatisticalService;

/**
 * 
 * 统计
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-06-22 13:54:15
 */
 
@Controller
@RequestMapping("/shop/Statistical")
public class StatisticalController {
	
	@Autowired
	private StatisticalService statisticalService;
	
	@Autowired
	private OhOrderService ohOrderService;
	
	/**
	 * 统计
	 * @Title: statistical   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@GetMapping()
	String statistical(){
		return "shop/statistical/statistical";
	}
	
	@GetMapping("/statistical")
	@ResponseBody
	public Map<String, Object> statisticalshow(String type){
		Map<String, Object> map = new HashMap<>();
		if(!"".equals(type)){
			map.put("type", type);
		}
		Map<String, Object> map1 = new HashMap<>();
		map1.put("countordermember", statisticalService.countordermember(map).get("countordermember"));
		map1.put("countorder", statisticalService.countorder(map).get("countorder"));
		map1.put("countamount", statisticalService.countamount(map).get("countamount"));
		map1.put("countsuccess", statisticalService.countsuccess(map).get("countsuccess"));
		map1.put("paymoney", statisticalService.paymoney(map).get("paymoney"));
		map1.put("countpayordermember", statisticalService.countpayordermember(map).get("countpayordermember"));
		map1.put("countpayorder", statisticalService.countpayorder(map).get("countpayorder"));
		map1.put("countpayamount", statisticalService.countpayamount(map).get("countpayamount"));
		map1.put("countpaymoney", statisticalService.countpaymoney(map).get("countpaymoney"));
		map1.put("average", statisticalService.average(map).get("average"));
		return map1;
	}
	
	/**
	 * 综合统计
	 * @Title: comprehensive_statistics   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@GetMapping("/comprehensive_statistics")
	String comprehensive_statistics(){
		return "shop/statistical/comprehensive";
	}
	
	@GetMapping("/comprehensive")
	@ResponseBody
	public Map<String, Object> comprehensive(String type){
		Map<String, Object> map = new HashMap<>();
		if(!"".equals(type)){
			map.put("type", type);
		}
		Map<String, Object> map1 = new HashMap<>();
		map1.put("paymoney", statisticalService.paymoney(map).get("paymoney"));
		map1.put("countsuccess", statisticalService.countsuccess(map).get("countsuccess"));
		map1.put("validpaymoney", statisticalService.validpaymoney(map).get("validpaymoney"));
		map1.put("invalidcount", statisticalService.invalidcount(map).get("invalidcount"));
		map1.put("invalidpaymoney", statisticalService.invalidpaymoney(map).get("invalidpaymoney"));
		map1.put("endordercount", statisticalService.endordercount(map).get("endordercount"));
		map1.put("endordermoneycount", statisticalService.endordermoneycount(map).get("endordermoneycount"));
		
		
		map1.put("isvipcount", statisticalService.isvipcount(map).get("isvipcount"));
		map1.put("orderisvip", statisticalService.orderisvip(map).get("orderisvip"));
		map1.put("isviporder", statisticalService.isviporder(map).get("isviporder"));
		map1.put("noisviporder", statisticalService.noisviporder(map).get("noisviporder"));
		map1.put("vippaymoneycount", statisticalService.vippaymoneycount(map).get("vippaymoneycount"));
		map1.put("novippaymoneycount", statisticalService.novippaymoneycount(map).get("novippaymoneycount"));
		map1.put("vippurchaserate", statisticalService.vippurchaserate(map).get("vippurchaserate"));
		
		map1.put("youbicount", statisticalService.youbicount(map).get("youbicount"));
		return map1;
	}
	
	
	@GetMapping("/order")
	String OhOrder(){
	    return "shop/statistical/ohOrder";
	}
	
	@ResponseBody
	@GetMapping("/listorder")
	public PageUtils listorder(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OhOrderDO> ohOrderList = statisticalService.listorder(query);
		List<OhOrderDO> OhOrderDOList2 = new ArrayList<>();
		for (OhOrderDO ohOrderDO : ohOrderList) {
			ohOrderDO.setProductNameAndNumber(ohOrderService.orderProductNameAndNumber(ohOrderDO.getId()));
			OhOrderDOList2.add(ohOrderDO);
		}
		int total = statisticalService.ordercount(query);
		PageUtils pageUtils = new PageUtils(OhOrderDOList2, total);
		return pageUtils;
	}
	
	@GetMapping("/orderproduct")
	String OrderProduct(Long id,Model model){
	    return "shop/statistical/orderProduct";
	}
	
	@ResponseBody
	@GetMapping("/listorderproduct")
	public PageUtils listorderproduct(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderProductDO> orderProductList = statisticalService.listOrderProduct(query);
		int total = statisticalService.OrderProductcount(query);
		PageUtils pageUtils = new PageUtils(orderProductList, total);
		return pageUtils;
	}
}
